using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.MedicalDomain;
using ShivamEMR.Model.DataInterfaces.MedicalDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.Medical.Controllers
{   
    public class DiseaseGroupController : Controller
    {
		private readonly IDiseaseGroupRepository diseasegroupRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public DiseaseGroupController()// : this(new DiseaseGroupRepository())
        {
            this.diseasegroupRepository = Registry.RepositoryFactory.GetDiseaseGroupRepository();
        }

        public DiseaseGroupController(IDiseaseGroupRepository diseasegroupRepository)
        {
			this.diseasegroupRepository = diseasegroupRepository;
        }

        //
        // GET: /DiseaseGroup/

        public ViewResult Index()
        {
            return View(diseasegroupRepository.All);//Including(diseasegroup => diseasegroup.Parent, diseasegroup => diseasegroup.Children, diseasegroup => diseasegroup.Diseases));
        }

        //
        // GET: /DiseaseGroup/Details/5

        public ViewResult Details(int id)
        {
            return View(diseasegroupRepository.Find(id));
        }

        //
        // GET: /DiseaseGroup/Create

        public ActionResult Create()
        {
			ViewBag.PossibleParents = diseasegroupRepository.All;
            return View();
        } 

        //
        // POST: /DiseaseGroup/Create

        [HttpPost]
        public ActionResult Create(DiseaseGroup diseasegroup)
        {
            if (ModelState.IsValid) {
                diseasegroupRepository.InsertOrUpdate(diseasegroup);
                diseasegroupRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleParents = diseasegroupRepository.All;
				return View();
			}
        }
        
        //
        // GET: /DiseaseGroup/Edit/5
 
        public ActionResult Edit(int id)
        {
			ViewBag.PossibleParents = diseasegroupRepository.All;
             return View(diseasegroupRepository.Find(id));
        }

        //
        // POST: /DiseaseGroup/Edit/5

        [HttpPost]
        public ActionResult Edit(DiseaseGroup diseasegroup)
        {
            if (ModelState.IsValid) {
                diseasegroupRepository.InsertOrUpdate(diseasegroup);
                diseasegroupRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleParents = diseasegroupRepository.All;
				return View();
			}
        }

        //
        // GET: /DiseaseGroup/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(diseasegroupRepository.Find(id));
        }

        //
        // POST: /DiseaseGroup/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            var d = diseasegroupRepository.Find(id);
            diseasegroupRepository.Delete(d);
            diseasegroupRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

